<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
    <title>Coverage Report :: Clyde</title>
    <style type="text/css">
        @import "../../.css/coverage.css";
    </style>
</head>

<body>
<div class="header"></div>

<div class="content">
    <div class="breadCrumbs">
        [ <a href="../../index.html">all classes</a> ]
        [ <a href="../index.html">nl.tudelft.jpacman.npc.ghost</a> ]
    </div>

    <h1>Coverage Summary for Class: Clyde (nl.tudelft.jpacman.npc.ghost)</h1>

    <table class="coverageStats">
        <tr>
            <th class="name">Class</th>
            <th class="coverageStat
">
                Class, %
            </th>
            <th class="coverageStat
">
                Method, %
            </th>
            <th class="coverageStat
">
                Line, %
            </th>
        </tr>
        <tr>
            <td class="name">Clyde</td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 1)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 3)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 20)
  </span>
            </td>
        </tr>

    </table>

    <br/>
    <br/>


    <div class="sourceCode"><i>1</i>&nbsp;package nl.tudelft.jpacman.npc.ghost;
        <i>2</i>&nbsp;
        <i>3</i>&nbsp;import java.util.EnumMap;
        <i>4</i>&nbsp;import java.util.List;
        <i>5</i>&nbsp;import java.util.Map;
        <i>6</i>&nbsp;import java.util.Optional;
        <i>7</i>&nbsp;
        <i>8</i>&nbsp;import nl.tudelft.jpacman.board.Direction;
        <i>9</i>&nbsp;import nl.tudelft.jpacman.board.Square;
        <i>10</i>&nbsp;import nl.tudelft.jpacman.board.Unit;
        <i>11</i>&nbsp;import nl.tudelft.jpacman.level.Player;
        <i>12</i>&nbsp;import nl.tudelft.jpacman.npc.Ghost;
        <i>13</i>&nbsp;import nl.tudelft.jpacman.sprite.Sprite;
        <i>14</i>&nbsp;
        <i>15</i>&nbsp;/**
        <i>16</i>&nbsp; * &lt;p&gt;
        <i>17</i>&nbsp; * An implementation of the classic Pac-Man ghost Clyde.
        <i>18</i>&nbsp; * &lt;/p&gt;
        <i>19</i>&nbsp; * &lt;p&gt;
        <i>20</i>&nbsp; * Pokey needs a new nickname because out of all the ghosts,
        <i>21</i>&nbsp; * Clyde is the least likely to &quot;C&#39;lyde&quot; with Pac-Man. Clyde is always the last
        <i>22</i>&nbsp; * ghost out of the regenerator, and the loner of the gang, usually off doing
        <i>23</i>&nbsp; * his own thing when not patrolling the bottom-left corner of the maze. His
        <i>24</i>&nbsp; * behavior is very random, so while he&#39;s not likely to be following you in hot
        <i>25</i>&nbsp; * pursuit with the other ghosts, he is a little less predictable, and still a
        <i>26</i>&nbsp; * danger.
        <i>27</i>&nbsp; * &lt;/p&gt;
        <i>28</i>&nbsp; * &lt;p&gt;
        <i>29</i>&nbsp; * &lt;b&gt;AI:&lt;/b&gt; Clyde has two basic AIs, one for when he&#39;s far from Pac-Man, and
        <i>30</i>&nbsp; * one for when he is near to Pac-Man.
        <i>31</i>&nbsp; * When Clyde is far away from Pac-Man (beyond eight grid spaces),
        <i>32</i>&nbsp; * Clyde behaves very much like Blinky, trying to move to Pac-Man&#39;s exact
        <i>33</i>&nbsp; * location. However, when Clyde gets within eight grid spaces of Pac-Man, he
        <i>34</i>&nbsp; * automatically changes his behavior and runs away.
        <i>35</i>&nbsp; * &lt;/p&gt;
        <i>36</i>&nbsp; * &lt;p&gt;
        <i>37</i>&nbsp; * Source: http://strategywiki.org/wiki/Pac-Man/Getting_Started
        <i>38</i>&nbsp; * &lt;/p&gt;
        <i>39</i>&nbsp; *
        <i>40</i>&nbsp; * @author Jeroen Roosen
        <i>41</i>&nbsp; */
        <b class="nc"><i>42</i>&nbsp;public class Clyde extends Ghost {</b>
        <i>43</i>&nbsp;
        <i>44</i>&nbsp; /**
        <i>45</i>&nbsp; * The amount of cells Clyde wants to stay away from Pac Man.
        <i>46</i>&nbsp; */
        <i>47</i>&nbsp; private static final int SHYNESS = 8;
        <i>48</i>&nbsp;
        <i>49</i>&nbsp; /**
        <i>50</i>&nbsp; * The variation in intervals, this makes the ghosts look more dynamic and
        <i>51</i>&nbsp; * less predictable.
        <i>52</i>&nbsp; */
        <i>53</i>&nbsp; private static final int INTERVAL_VARIATION = 50;
        <i>54</i>&nbsp;
        <i>55</i>&nbsp; /**
        <i>56</i>&nbsp; * The base movement interval.
        <i>57</i>&nbsp; */
        <i>58</i>&nbsp; private static final int MOVE_INTERVAL = 250;
        <i>59</i>&nbsp;
        <i>60</i>&nbsp; /**
        <i>61</i>&nbsp; * A map of opposite directions.
        <i>62</i>&nbsp; */
        <b class="nc"><i>63</i>&nbsp; private static final Map&lt;Direction, Direction&gt; OPPOSITES = new EnumMap&lt;&gt;(Direction.class);</b>
        <i>64</i>&nbsp;
        <i>65</i>&nbsp; static {
        <b class="nc"><i>66</i>&nbsp; OPPOSITES.put(Direction.NORTH, Direction.SOUTH);</b>
        <b class="nc"><i>67</i>&nbsp; OPPOSITES.put(Direction.SOUTH, Direction.NORTH);</b>
        <b class="nc"><i>68</i>&nbsp; OPPOSITES.put(Direction.WEST, Direction.EAST);</b>
        <b class="nc"><i>69</i>&nbsp; OPPOSITES.put(Direction.EAST, Direction.WEST);</b>
        <i>70</i>&nbsp; }
        <i>71</i>&nbsp;
        <i>72</i>&nbsp; /**
        <i>73</i>&nbsp; * Creates a new &quot;Clyde&quot;, a.k.a. &quot;Pokey&quot;.
        <i>74</i>&nbsp; *
        <i>75</i>&nbsp; * @param spriteMap The sprites for this ghost.
        <i>76</i>&nbsp; */
        <i>77</i>&nbsp; public Clyde(Map&lt;Direction, Sprite&gt; spriteMap) {
        <b class="nc"><i>78</i>&nbsp; super(spriteMap, MOVE_INTERVAL, INTERVAL_VARIATION);</b>
        <i>79</i>&nbsp; }
        <i>80</i>&nbsp;
        <i>81</i>&nbsp; /**
        <i>82</i>&nbsp; * {@inheritDoc}
        <i>83</i>&nbsp; *
        <i>84</i>&nbsp; * &lt;p&gt;
        <i>85</i>&nbsp; * Clyde has two basic AIs, one for when he&#39;s far from Pac-Man, and one for
        <i>86</i>&nbsp; * when he is near to Pac-Man.
        <i>87</i>&nbsp; * When Clyde is far away from Pac-Man (beyond eight grid spaces),
        <i>88</i>&nbsp; * Clyde behaves very much like Blinky, trying to move to Pac-Man&#39;s exact
        <i>89</i>&nbsp; * location. However, when Clyde gets within eight grid spaces of Pac-Man,
        <i>90</i>&nbsp; * he automatically changes his behavior and runs away
        <i>91</i>&nbsp; * &lt;/p&gt;
        <i>92</i>&nbsp; */
        <i>93</i>&nbsp; @Override
        <i>94</i>&nbsp; public Optional&lt;Direction&gt; nextAiMove() {
        <b class="nc"><i>95</i>&nbsp; assert hasSquare();</b>
        <i>96</i>&nbsp;
        <b class="nc"><i>97</i>&nbsp; Unit nearest = Navigation.findNearest(Player.class, getSquare());</b>
        <b class="nc"><i>98</i>&nbsp; if (nearest == null) {</b>
        <b class="nc"><i>99</i>&nbsp; return Optional.empty();</b>
        <i>100</i>&nbsp; }
        <b class="nc"><i>101</i>&nbsp; assert nearest.hasSquare();</b>
        <b class="nc"><i>102</i>&nbsp; Square target = nearest.getSquare();</b>
        <i>103</i>&nbsp;
        <b class="nc"><i>104</i>&nbsp; List&lt;Direction&gt; path = Navigation.shortestPath(getSquare(), target, this);</b>
        <i>105</i>&nbsp;
        <b class="nc"><i>106</i>&nbsp; if (path != null &amp;&amp; !path.isEmpty()) {</b>
        <b class="nc"><i>107</i>&nbsp; Direction direction = path.get(0);</b>
        <b class="nc"><i>108</i>&nbsp; if (path.size() &lt;= SHYNESS) {</b>
        <b class="nc"><i>109</i>&nbsp; return Optional.ofNullable(OPPOSITES.get(direction));</b>
        <i>110</i>&nbsp; }
        <b class="nc"><i>111</i>&nbsp; return Optional.of(direction);</b>
        <i>112</i>&nbsp; }
        <b class="nc"><i>113</i>&nbsp; return Optional.empty();</b>
        <i>114</i>&nbsp; }
        <i>115</i>&nbsp;
        <i>116</i>&nbsp;}
    </div>
</div>

<div class="footer">

    <div style="float:right;">generated on 2023-04-25 16:45</div>
</div>
</body>
</html>
